package com.lsfb.signsys.my;

import android.app.ActivityManager;

import com.lsfb.signsys.compatible.LsfbLog;
import com.lsfb.signsys.utils.Utils;
import com.lsfb.signsys.view.BottomNavView.BageWrapper;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by zgscwjm on 2018/3/30.
 */

public class MyPresenter implements MyContract.Presenter {

    private MyContract.MyView myView;

    private CompositeDisposable mCompositeDisposable;

    private MyRepository mMyRepository;

    public MyPresenter(MyContract.MyView myView) {
        this.myView = myView;
        mCompositeDisposable = new CompositeDisposable();
        mMyRepository = new MyRepository();


        //将自己与view捆绑起来
        myView.setPresenter(this);
    }




    @Override
    public void subscribe() {


        Utils.getInstall().getUPdate().subscribe(b->{
            myView.binderBaseInfo(b.getHeadImg(), b.getUserName(), b.getJobsName());
        });


        baseInfo();

    }

    @Override
    public void unsubscribe() {
        mCompositeDisposable.clear();
    }


    @Override
    public void logout() {
//        Utils.getInstall().subscript(b->{
//            myView.binderBaseInfo(b.getHeadImg(), b.getUserName(), b.getJobsName());
//        });



    }

    @Override
    public void editpwd() {
        myView.showEidtPwdActivity();
    }

    @Override
    public void editfaceImg() {
        myView.showFaceImgEditActivity();
    }

    @Override
    public void feedback() {
//        Utils.getInstall().getInfoBean().subscribe(b->{
//            b.setUserName("zgscwjm");
//        });

        MyInfoBean myInfoBean = new MyInfoBean();
        myInfoBean.setUserName("1312321");
        myInfoBean.setJobsName("是的发送到");
        Utils.getInstall().updateUser(myInfoBean);
    }

    @Override
    public void baseInfo() {
        mCompositeDisposable.clear();
        Disposable disposable = mMyRepository.getInfo().subscribe(myInfoBean -> {
//                    Utils.getInstall().setInfoBean(myInfoBean);
                    Utils.getInstall().updateUser(myInfoBean);
                },
                e -> {
                }, () -> {

                }
        );
        mCompositeDisposable.add(disposable);
    }
}
